package com.haochang.chunkvod.tools.vod.thread;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

/**
 * @author qintao
 *         created at 2016/11/18 20:32
 *         首页执行多个动画的线程
 */

public class FlickThread extends Thread
{
	/**
	 * 动画执行集合
	 */
	private List<View> viewStartList = new ArrayList<View>();
	/**
	 * 动画停止集合
	 */
	private List<View> viewStopList = new ArrayList<View>();

	public FlickThread(List<View> viewStartList, List<View> viewStopList)
	{
		this.viewStartList = viewStartList;
		this.viewStopList = viewStopList;
	}

	@Override
	public void run()
	{
		super.run();
		stopAnimations();
		startAnimations();
	}

	private void startAnimations()
	{
		for (int i = 0; i < viewStartList.size(); i++)
		{
			startFlick(viewStartList.get(i));
		}
	}

	private void stopAnimations()
	{
		for (int i = 0; i < viewStopList.size(); i++)
		{
			stopFlick(viewStopList.get(i));
		}
	}

	private void startFlick(View view)
	{
		if (null == view)
			return;
		Animation alphaAnimation = new AlphaAnimation(1, 0.4f);
		alphaAnimation.setDuration(500);
		alphaAnimation.setRepeatCount(Animation.INFINITE);
		alphaAnimation.setRepeatMode(Animation.REVERSE);
		view.startAnimation(alphaAnimation);
	}

	/**
	 * 清除动画
	 *
	 * @param view
	 */
	private void stopFlick(View view)
	{
		if (null == view)
			return;
		view.clearAnimation();
	}
}
